// Otto by the IdeaLab FabLab
// =====================================================
// SATSUMA (TURTLE) — BODY + LEGS (COEFF-SCALED)
// - Body: octagon + servo cutouts ONLY
// - Legs: separate pieces with SG90 horn screw hole
// - ALL geometry scaled by coeff = 3/4
// =====================================================


// -------------------- GLOBAL SCALE --------------------
param coeff 3/4


// -------------------- MATERIAL & FIT PARAMS --------------------
param materialThickness0 3
param kerf0 0.20
param clearance0 0.15

param materialThickness (materialThickness0 * coeff)
param kerf (kerf0 * coeff)
param clearance (clearance0 * coeff)


// -------------------- SERVO PARAMS (SG90 BODY CUTOUT) --------------------
// Actual SG90 body: 22.5 (long) × 11.5 (short)
param servoW0 11.5 + kerf0 + clearance0
param servoH0 22.5 + kerf0 + clearance0

param servoW (servoW0 * coeff)
param servoH (servoH0 * coeff)



// -------------------- BODY PARAMS --------------------
param bodySides 8

param bodyR0 80
param bodyR (bodyR0 * coeff)

param bodyRot 22.5   // rotation is angular → NOT scaled

param legServoOffset (bodyR * 0.65454545455)
param headServoOffset (bodyR * 0.73333333333)


// -------------------- ANGLE HELPERS --------------------
param c45  0.70710678
param s45  0.70710678

param c135 -0.70710678
param s135  0.70710678

param c225 -0.70710678
param s225 -0.70710678

param c315  0.70710678
param s315 -0.70710678



// =====================================================
// BODY BASE (OCTAGON)
// =====================================================
shape polygon satsuma_body_base {
  position: [0, 0]
  sides: bodySides
  radius: bodyR
  rotation: bodyRot
  fill: false
}


// =====================================================
// SERVO CUTOUTS (BODY ONLY — NO HOLES)
// =====================================================
shape roundedRectangle leg_servo_45 {
  position: [legServoOffset*c45, legServoOffset*s45]
  width: servoW
  height: servoH
  radius: -20
  rotation: 45
  fill: false
}

shape roundedRectangle leg_servo_135 {
  position: [legServoOffset*c135, legServoOffset*s135]
  width: servoW
  height: servoH
  radius: -20
  rotation: 135
  fill: false
}

shape roundedRectangle leg_servo_225 {
  position: [legServoOffset*c225, legServoOffset*s225]
  width: servoW
  height: servoH
  radius: -20
  rotation: 225
  fill: false
}

shape roundedRectangle leg_servo_315 {
  position: [legServoOffset*c315, legServoOffset*s315]
  width: servoW
  height: servoH
  radius: -20
  rotation: 315
  fill: false
}

// head servo cutout
shape roundedRectangle head_servo_0 {
  position: [0, headServoOffset]
  width: servoW
  height: servoH
  radius: -20
  rotation: 0
  fill: false
}


// =====================================================
// FINAL BODY
// =====================================================
difference satsuma_body {
  add satsuma_body_base

  add leg_servo_45
  add leg_servo_135
  add leg_servo_225
  add leg_servo_315

  add head_servo_0
}



// =====================================================
// LEGS (4x) — SG90 HORN SCREW HOLE ONLY
// =====================================================

// -------------------- LEG PARAMS --------------------
param legLen0 95
param legW0 24
param legR0 12

param legLen (legLen0 * coeff)
param legW   (legW0 * coeff)
param legR   (legR0 * coeff)

param hornHoleR0 2.3
param hornInset0 18

param hornHoleR (hornHoleR0 * coeff)
param hornInset (hornInset0 * coeff)


// -------------------- LEG LAYOUT --------------------
param legsBaseX (bodyR + 120*coeff)
param legsBaseY (-bodyR - 40*coeff)
param legsGapY (legW + 14*coeff)


// ----- LEG 0 -----
shape roundedRectangle leg_blank_0 {
  position: [legsBaseX, legsBaseY + 0*legsGapY]
  width: legLen
  height: legW
  radius: legR
  fill: false
}

shape circle leg_hole_0 {
  position: [legsBaseX - legLen/2 + hornInset, legsBaseY + 0*legsGapY]
  radius: hornHoleR
  fill: false
}

difference satsuma_leg_0 {
  add leg_blank_0
  add leg_hole_0
}


// ----- LEG 1 -----
shape roundedRectangle leg_blank_1 {
  position: [legsBaseX, legsBaseY + 1*legsGapY]
  width: legLen
  height: legW
  radius: legR
  fill: false
}

shape circle leg_hole_1 {
  position: [legsBaseX - legLen/2 + hornInset, legsBaseY + 1*legsGapY]
  radius: hornHoleR
  fill: false
}

difference satsuma_leg_1 {
  add leg_blank_1
  add leg_hole_1
}


// ----- LEG 2 -----
shape roundedRectangle leg_blank_2 {
  position: [legsBaseX, legsBaseY + 2*legsGapY]
  width: legLen
  height: legW
  radius: legR
  fill: false
}

shape circle leg_hole_2 {
  position: [legsBaseX - legLen/2 + hornInset, legsBaseY + 2*legsGapY]
  radius: hornHoleR
  fill: false
}

difference satsuma_leg_2 {
  add leg_blank_2
  add leg_hole_2
}


// ----- LEG 3 -----
shape roundedRectangle leg_blank_3 {
  position: [legsBaseX, legsBaseY + 3*legsGapY]
  width: legLen
  height: legW
  radius: legR
  fill: false
}

shape circle leg_hole_3 {
  position: [legsBaseX - legLen/2 + hornInset, legsBaseY + 3*legsGapY]
  radius: hornHoleR
  fill: false
}

difference satsuma_leg_3 {
  add leg_blank_3
  add leg_hole_3
}
